package com.example.springbook.model;

import com.example.springbook.enums.ResultStatus;
import lombok.Data;

@Data
public class Result<T> {
    private ResultStatus code;
    private String errMsg;
    private T date;
    public static <T> Result success(T date){
        Result<T> result=new Result<>();
        result.setCode(ResultStatus.SUCCESS);
        result.setDate(date);
        return result;
    }
    public static Result nologin(){
        Result result = new Result<>();
        result.setCode(ResultStatus.NOLOGIN);
        result.setErrMsg("用户未登录");
        return result;
    }
    public static Result fail(String msg){
        Result result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(msg);
        return result;
    }

    public static Result fail(ResultStatus resultStatus, String msg){
        Result result = new Result<>();
        result.setCode(resultStatus);
        result.setErrMsg(msg);
        return result;
    }
}
